package com.yuwubao.uav.tool.service.impl;

import com.yuwubao.framework.bean.PageData;
import com.yuwubao.uav.tool.mapper.QuestionnaireMapper;
import com.yuwubao.uav.tool.service.QuestionnaireService;
import com.yuwubao.uav.tool.util.StringUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Service
public class QuestionnaireServiceImpl implements QuestionnaireService {

    private static final Logger logger = LogManager.getLogger(QuestionnaireServiceImpl.class.getName());

    @Resource
    private QuestionnaireMapper questionnaireMapper;

    @Override
    public void deleteQuestionnaire(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    questionnaireMapper.deleteQuestionnaire(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateQuestionnaire(PageData pageData) throws Exception {
        try{
            questionnaireMapper.updateQuestionnaire(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnableQuestionnaire(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    questionnaireMapper.disableOrEnableQuestionnaire(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void addQuestionnaire(PageData pageData) throws Exception {
        try{
            questionnaireMapper.addQuestionnaire(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listQuestionnaire(PageData pageData) throws Exception {
        try{
            return questionnaireMapper.listQuestionnaire(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listQuestionnaireCount(PageData pageData) throws Exception {
        try{
            return questionnaireMapper.listQuestionnaireCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }

    //题目类型=====================

    @Override
    public void deleteQuestionnaireSubType(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    questionnaireMapper.deleteQuestionnaireSubType(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateQuestionnaireSubType(PageData pageData) throws Exception {
        try{
            questionnaireMapper.updateQuestionnaireSubType(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnableQuestionnaireSubType(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    questionnaireMapper.disableOrEnableQuestionnaireSubType(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void addQuestionnaireSubType(PageData pageData) throws Exception {
        try{
            questionnaireMapper.addQuestionnaireSubType(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listQuestionnaireSubType(PageData pageData) throws Exception {
        try{
            return questionnaireMapper.listQuestionnaireSubType(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listQuestionnaireSubTypeCount(PageData pageData) throws Exception {
        try{
            return questionnaireMapper.listQuestionnaireSubTypeCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }

    @Override
    public List<PageData> listQuestionnaireSubTypeAll(PageData pageData) throws Exception {
        try{
            return questionnaireMapper.listQuestionnaireSubTypeAll(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }

    // 题目

    @Override
    public void deleteQuestionnaireSubject(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    questionnaireMapper.deleteQuestionnaireSubject(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateQuestionnaireSubject(PageData pageData) throws Exception {
        try{
            questionnaireMapper.updateQuestionnaireSubject(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnableQuestionnaireSubject(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    questionnaireMapper.disableOrEnableQuestionnaireSubject(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void addSubjectForQuestionnaire(PageData pageData) throws Exception {
        try{
            questionnaireMapper.addSubjectForQuestionnaire(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void addQuestionnaireSubject(PageData pageData) throws Exception {
        try{
            questionnaireMapper.addQuestionnaireSubject(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }


    @Override
    public List<PageData> listQuestionnaireSubjectAll(PageData pageData) throws Exception {
        try{
            List<PageData> qList = questionnaireMapper.listQuestionnaireSubjectAll(pageData);
            if (qList!= null && qList.size()>0) {
                for (PageData pd : qList) {
                    pd.put("subId",pd.get("id"));
                    pd.put("optionList",questionnaireMapper.listQuestionnaireOptionAll(pd));
                }
            }
            return qList;
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }

    // 选项

    @Override
    public void deleteQuestionnaireOption(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    questionnaireMapper.deleteQuestionnaireOption(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateQuestionnaireOption(PageData pageData) throws Exception {
        try{
            questionnaireMapper.updateQuestionnaireOption(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnableQuestionnaireOption(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    questionnaireMapper.disableOrEnableQuestionnaireOption(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void addQuestionnaireOption1(PageData pageData) throws Exception {
        try{
            questionnaireMapper.addQuestionnaireOption1(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void addQuestionnaireOption(PageData pageData) throws Exception {
        try{
            questionnaireMapper.addQuestionnaireOption(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }


    @Override
    public List<PageData> listQuestionnaireOptionAll(PageData pageData) throws Exception {
        try{
            return questionnaireMapper.listQuestionnaireOptionAll(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }



}
